package com.lpgu.repositories;

import com.lpgu.MyJpaProxy;

import javax.persistence.EntityManager;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author: lpgu
 * @describe:MyJpaRepository
 * @createAt: 2022/1/3 17:55
 */
public class MyJpaRepository implements InvocationHandler {

    private EntityManager entityManager;
    private Class pojoClass;

    public MyJpaRepository(EntityManager entityManager, Class pojoClass) {
        this.entityManager = entityManager;
        this.pojoClass = pojoClass;
    }
//method 当前处理方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("查询。。。。。。。。。。。");
        MyJpaProxy myJpaProxy = new MyJpaProxy(entityManager, pojoClass);
        Method targetMethod = myJpaProxy.getClass().getMethod(method.getName(), method.getParameterTypes());
        return targetMethod.invoke(myJpaProxy,args);
    }
}
